package com.remist.web.action;

import org.apache.struts2.ServletActionContext;

import com.remist.model.Member;
import com.remist.service.MemberService;

public class MemberAction extends BaseAction {
	/**	serialVersionUID */
	private static final long serialVersionUID = 1L;
	public MemberService memberService;
	private Member member;
	private String sessionKey;
	public String getSessionKey() {
		return sessionKey;
	}

	public void setSessionKey(String sessionKey) {
		this.sessionKey = sessionKey;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public String register() throws Exception {
		Object sessionObj = ServletActionContext.getRequest ().getSession().getAttribute("sessionKey");
		if ( sessionObj != null &&    sessionObj.toString().equalsIgnoreCase( sessionKey ) ){
			memberService.addMember(member);
			ServletActionContext.getRequest ().getSession().setAttribute("member", member);
			ServletActionContext.getRequest ().getSession().removeAttribute("sessionKey");
		}
		return SUCCESS;
	}
	public String checkMember() throws Exception {
		member = memberService.checkEmailAndPassword(member);
		if ( member != null ){
			ServletActionContext.getRequest ().getSession().setAttribute("member", member);
			return SUCCESS;
		} else {
			return ERROR;
		}
	}

	public MemberService getMemberService() {
		return memberService;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}
	
	
	
}
